<template>

  <div>
    <el-dialog :close-on-click-modal="false" title="考试结果" class="tl size_13" width="90%" :visible.sync="dialogResultVisible">
      <div>
        <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" :isShow="true" :navTitleShow="false" @sendUserSearch="receive_search" :searchData="searchDataInfo" :isHaveExport="false" :isHaveAdd="false" @toAdd="openAdd">
          <template v-slot:table>
            <el-table ref="multipleTable" :data="list.data" stripe v-loading="tableLoading" header-row-class-name="head_color" tooltip-effect="dark" style="width: 99.8%" @selection-change="handleSelectionChange">
              <el-table-column type="selection" class="tc" width="35"></el-table-column>
              <el-table-column label="头像" min-width="80">
                <template slot-scope="scope">
                  <div class="img_bor_tx">
                    <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
                  </div>
                </template>
              </el-table-column>

              <el-table-column label="用户信息" min-width="120">
                <template slot-scope="scope">
                  <div class="tab_div">
                    <div>
                      <span>用户昵称：</span>
                      <span>{{ scope.row.nickname || "----" }}</span>
                    </div>
                    <div>
                      <span>会员账号：</span>
                      <span>{{ scope.row.username || "---" }}</span>
                    </div>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="考试信息" min-width="180">
                <template slot-scope="scope">
                  <div class="tab_div">
                    <div>
                      <span>订单号：</span>
                      <span>{{ scope.row.oid || "----" }}</span>
                    </div>
                    <div>
                      <span>分数：</span>
                      <span>{{ scope.row.fraction || "----" }}</span>
                    </div>
                    <div>
                      <span>用时：</span>
                      <span>{{ formatSeconds(scope.row.duration) || "---" }}</span>
                    </div>
                  </div>
                </template>
              </el-table-column>

              <!-- <el-table-column label="激活" min-width="65">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.show" active-color="#1aad19" inactive-color="#ffffff" active-text="on" inactive-text="off" active-value="1" @change="handleSwitch($event, scope.row)" inactive-value="0"></el-switch>
            </template>
          </el-table-column> -->
              <el-table-column label="时间信息" min-width="120">
                <template slot-scope="scope">
                  <div class="tab_div">
                    <div>
                      <span>添加时间：</span>
                      <span>{{ scope.row.created_time | getTimeFormat }}</span>
                    </div>
                    <div>
                      <span>修改时间：</span>
                      <span>{{ scope.row.update_time | getTimeFormat }}</span>
                    </div>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="操作" min-width="120">
                <template slot-scope="scope">
                  <el-row class="myblank">
                    <el-button :loading="$store.state.isLoading" size="mini" @click="openEdit(scope.row)" type="primary">查看答题</el-button>
                    <el-button :loading="$store.state.isLoading" size="mini" type="danger" @click="openDelete(scope.row.id)">删除</el-button>
                  </el-row>
                </template>
              </el-table-column>
            </el-table>
          </template>
          <template v-slot:footerLeft>
            <a class="aBtn aBtn_1 aBtn_lan2" @click="moreDelete">删除</a>
            <!--  <a class="aBtn aBtn_1 aBtn_lan2" style="background: #f56c6c;" @click="getNewsAll()">刷新</a> -->
          </template>
        </tableComponents>

      </div>
    </el-dialog>

    <el-dialog :close-on-click-modal="false" title="查看答题" class="tl size_13" width="800px" :visible.sync="dialogFormVisible">
      <div v-for="(item,i) in edit_data.answer" :key="i" style="line-height:2">
        <div>问题：{{item.title.title}}</div>
        <div :style="{color:item.title.answer == item.answer ? '#67C23A':'#F56C6C'}">回答：{{item.answer}}
          <i class="el-icon-check" v-if="item.title.answer == item.answer"></i>
          <i class="el-icon-close" v-else></i>
        </div>
        <el-divider></el-divider>
      </div>
    </el-dialog>
  </div>
</template>
<script>
// import xzuser from "@/components/currency/xz_user.vue";
import uploadpic from "@/components/page/pic/up_pic";
import { collegeUserRecordSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data() {
    return {
      loadding1: true,
      searchDataInfo: collegeUserRecordSearchData,
      current: "",
      shows: false,
      isEdit: false,
      dialogFormVisible: false,
      edit_data: {
        piclink: "",
      },
      tableLoading: false,
      list: [],
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      multipleSelection: [],
      editID: "",
      dialogResultVisible: false,
    };
  },
  components: {
    uploadpic,
  },
  methods: {
    formatSeconds(value) {
      var secondTime = parseInt(value); // 秒
      var minuteTime = 0; // 分
      var hourTime = 0; // 小时
      if (secondTime > 60) {
        //如果秒数大于60，将秒数转换成整数
        //获取分钟，除以60取整数，得到整数分钟
        minuteTime = parseInt(secondTime / 60);
        //获取秒数，秒数取余，得到整数秒数
        secondTime = parseInt(secondTime % 60);
        //如果分钟大于60，将分钟转换成小时
        if (minuteTime > 60) {
          //获取小时，获取分钟除以60，得到整数小时
          hourTime = parseInt(minuteTime / 60);
          //获取小时后取余的分，获取分钟除以60取余的分
          minuteTime = parseInt(minuteTime % 60);
        }
      }
      var result = "" + parseInt(secondTime) + "秒";
      if (minuteTime > 0) {
        result = "" + parseInt(minuteTime) + "分" + result;
      }
      if (hourTime > 0) {
        result = "" + parseInt(hourTime) + "小时" + result;
      }
      console.log("result", result);
      return result;
    },
    getShow(val) {
      this.shows = val;
    },
    getSend(info) {
      this.edit_data.username = info.username;
      this.edit_data.uid = info.id;
    },
    xzshop() {
      this.shows = true;
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    moreDelete() {
      //批量删除
      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思",
        }).then((willDelete) => {
          if (willDelete.value) {
            this.$api.getCollege
              .del_college_user_record({ id_str: str })
              .then((res) => {
                if (res.data.code == 200) {
                  this.$swal("删除成功！", res.data.result, "success");
                  this.getNewsAll();
                } else {
                  this.$swal("删除失败！", res.data.result, "error");
                }
              });
          }
        });
      }
    },
    openDelete(id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          this.$api.getCollege
            .del_college_user_record({ id_str: id })
            .then((res) => {
              if (res.data.code == 200) {
                this.$swal("删除成功！", res.data.result, "success");
                this.getNewsAll();
              } else {
                this.$swal("删除失败！", res.data.result, "error");
              }
            });
        }
      });
    },

    openAdd() {
      //   this.edit_data = {};
      //   this.isEdit = false;
      //   this.dialogFormVisible = true;
      let routeData = this.$router.resolve({
        path: "/index/college/college_user_record_edit",
        query: { did: this.editID },
      });
      window.open(routeData.href, "_blank");
    },
    onSuccess(pic) {
      this.edit_data.piclink = pic;
    },
    openEdit(item) {
      // this.isEdit = true;
      // this.edit_data = JSON.parse(JSON.stringify(item));
      // this.dialogFormVisible = true;
      this.$api.getCollege
        .single_college_user_record({ id: item.id })
        .then((res) => {
          if (res.data.code == 200) {
            this.edit_data = res.data.result;
            this.dialogFormVisible = true;
          }
        });
    },
    receive_search(obj) {
      this.currentPage = 1;
      this.searchAll = obj;
      this.getNewsAll();
    },
    handleSwitch(val, item) {
      var params = item;
      params.show = val;
      this.$api.getCollege.edit_college_user_record(params).then((res) => {
        if (res.data.code != 200) {
          this.$swal("编辑失败！", res.data.result, "error");
          this.getNewsAll();
        }
      });
    },

    sorta(a, b) {
      return b - a;
    },
    sortNew(index, item) {
      var params = item;
      params.sort = item.sort;
      this.$api.getCollege.edit_college_user_record(params).then((res) => {
        if (res.data.code == 200) {
          return;
        } else {
          this.$swal("编辑失败！", res.data.result, "error");
          this.getNewsAll();
        }
      });
    },
    saveEdit(item) {
      var params = {};
      params = JSON.parse(JSON.stringify(item));

      if (this.isEdit == false) {
        params.id = this.editID;
        this.$api.getCollege.add_college_user_record(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.loadding1 = true;
            this.currentPage = 1;
            this.getNewsAll();
            this.$swal("添加成功！", res.data.result, "success");
          } else {
            this.$swal("添加失败！", res.data.result, "error");
          }
        });
      } else {
        this.$api.getCollege.edit_college_user_record(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.loadding1 = true;
            this.getNewsAll();
            this.$swal("编辑成功！", res.data.result, "success");
          } else {
            this.$swal("编辑失败！", res.data.result, "error");
          }
        });
      }
    },
    getNewsAll() {
      this.tableLoading = true;
      var params = {};
      params = JSON.parse(JSON.stringify(this.searchAll));
      params.page = this.currentPage || 1;
      params.page_size = this.pageSize || "";
      for (var i in params) {
        if (!params[i]) {
          params[i] = "";
        }
      }
      var query = JSON.parse(JSON.stringify(this.queryObj || {}));
      var obj = Object.assign(query, params);
      obj.did = this.editID;
      this.$api.getCollege.get_college_user_record(obj).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        setTimeout(() => {
          this.tableLoading = false;
        }, 200);
      });
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.getNewsAll();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getNewsAll();
    },
    init(id) {
      this.editID = id;
      this.dialogResultVisible = true;
      this.getNewsAll();
    },
  },
  created() {},
  computed: {},
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}
</style>
